<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script type="text/javascript">
    function page(n, s) {
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchDrugFlowAccount").submit();
        return false;
    }
    $(function () {
        $("#btnCancel").on('click', function () {

        })
    })
</script>
<div class="app">
    <section class="layout">
        <section class="main-content">
            <div class="content-wrap">
                <div class="wrapper">
                    <ul class="nav nav-tabs">
                        <li>
                            <a href="#">药品销售记录查询</a>
                        </li>
                    </ul>
                    <section class="panel panel-default">
                        <div class="panel-body">
                            <div class="table-responsive no-border">
                                <div class="datatable-top">
                                    <div class="pull-left">
                                        <form:form id="searchDrugFlowAccount" modelAttribute="drugStock"
                                                   onsubmit="return loadDivForm('mainCenterDiv','searchDrugFlowAccount','${ctx}/drug/drugStock/drugFlowAccount');"
                                                   method="post" class="form-inline">

                                            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
                                            <input id="pageSize" name="pageSize" type="hidden"
                                                   value="${page.pageSize}"/>
                                            <%--<sys:treeselect selectedParent="true"   isnull="true" id="drugDispRec" name="wardCode"
                                                            value="${drugDispRec.wardCode}" update="false"
                                                            labelName="${drugDispRec.wardCode}"
                                                            labelValue="${drugDispRec.deptName}"
                                                            title="科室" url="/sys/orgDept/treeData"
                                                            cssClass="form-control"/>--%>
                                            <%--<form:input path="name" class="form-control" value="${drugDispRec.name}" placeholder="请输入患者姓名"/>--%>

                                                <label class=" control-label">药房：</label>
                                                <form:input path="storageName" id="storageName" style="width:15%" value="${drugStock.storageName}" htmlEscape="false" class="form-control"  maxlength="64"  />


                                                <label class=" control-label">药品名称：</label>
                                                <form:input path="drugNames" id="drugNames" style="width:15%" value="${drugStock.drugNames}" htmlEscape="false" class="form-control"  maxlength="64"/>


                                            <label class=" control-label">发药时间：</label>
                                            <input name="startTime" value="${drugStock.startTime}"
                                                   class="form-control Wdate" type="text" style="width:15%"
                                                   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                                   readonly="readonly"/>
                                            <label>至</label>
                                            <input name="endTime" value="${drugStock.endTime}"
                                                   class="form-control Wdate" type="text" style="width:15%"
                                                   readonly="readonly"
                                                   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>

                                            <input class="btn btn-primary" type="submit" value="发药查询"/>
                                            <input id="btnSubmit" class="btn btn-primary" type="button" value="退药查询" onclick="search()"/>
                                        </form:form>

                                    </div>
                                </div>
                                <table id="drugFlowAccountTable" class="table table-bordered mg-t datatable">
                                    <thead>
                                    <tr>
                                        <th>药品名</th>
                                        <th>药品规格</th>
                                        <th>药品单位</th>
                                        <th>药品厂商</th>
                                        <th>数量</th>
                                        <th>费用</th>
                                        <th>发药人</th>
                                        <th>领药人</th>
                                        <th>发药时间</th>
                                        <th>发药药房</th>

                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${page.list}" var="data">
                                        <tr style="text-align: center;">
                                            <td> ${data.drugNames}</td><%--药品名--%>
                                            <%--<td> ${data.orderText}</td>--%>
                                            <td> ${data.drugSpec}</td><%--药品规格--%>
                                            <td> ${fns:getDictLabel(data.drugUnits, 'SPEC_UNIT', '')}</td><%--药品单位--%>
                                            <td> ${data.firmName}</td><%--药品厂商--%>
                                            <td> ${data.amount} </td><%--数量--%>
                                            <td> ${data.costs}</td><%--费用--%>
                                            <td>${fns:getUserName(data.giveBy)}</td><%--发药人--%>
                                            <td>${data.acceptBy}</td><%--领药人--%>
                                            <td><fmt:formatDate value="${data.createDate}"
                                                                pattern="yyyy-MM-dd HH:mm:ss"/></td><%--发药时间--%>
                                            <td> ${data.storageName}</td><%--发药药房--%>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                                <div class="pagination">${page}</div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
    </section>
</div>
<script type="text/javascript">
        /*药房自动补全*/
        autoCompleteFirm();
        function autoCompleteFirm(inputId){
        var url="${ctx}/drug/drugStorageDept/findByMasterClass";
        $("#storageName").autocomplete(url, {
        minChars: 0, //在触发autoComplete前用户至少需要输入的字符数.
        max: 20,//autoComplete下拉显示项目的个数
        autoFill: false, //要不要在用户选择时自动将用户当前鼠标所在的值填入到input框
        //mustMatch: true, //autoComplete只会允许匹配的结果出现在输入框,所有当用户输入的是非法字符时将会得不到下拉框
        matchContains: true, //决定比较时是否要在字符串内部查看匹配,如ba是否与foo bar中的ba匹配.使用缓存时比较重要.不要和autofill混用
        multipleSeparator: '',//如果是多选时,用来分开各个选择的字符.
        multiple: false, //是否允许输入多个值即多次使用autoComplete以输入多个值
        scrollHeight: 300,
        width: "20%",
        dataType: 'json',
        method: 'POST',
        /*onBegin: function(options) { //修改--用于动态改变ledger的值
        options.extraParams.masterClass= $('#masterClassId').val();
        return options;
        },*/
        parse:  function(data){
        var rows = [];
        for(var i=0; i<data.length; i++){
        rows[rows.length] = {
        data:data[i],
        value:data[i].storageName,
        result:data[i].storageName
        };
        }
        return rows;
        }, formatItem: function(data, i, max){
        return data.storageName;
        }
        }).result(function(event,data,formatted){
        //$('#storageFrom').attr('value',data.storageName);
        });
        }


        /*药品自动补全*/
        autoCompleteDrugPrice("drugNames");
        function autoCompleteDrugPrice(inputId){
            var url="${ctx}/drug/drugInfo/autoCompletePrice";
            autoComplete(inputId,url,
                    function(data){
                        var rows = [];
                        for(var i=0; i<data.length; i++){
                            rows[rows.length] = {
                                data:data[i],
                                //value:data[i].id,
                                value:data[i].drugDict.drugName,
                                result:data[i].drugDict.drugName
                            };
                        }
                        return rows;
                    },function(data, i, max){
                        return data.drugDict.drugName+"|"+"|"+data.packageSpec+"|"+data.drugSupplierCata.supplierName;
                    },function(event,data,formatted){
                        console.log(data);

                        $('#drugNames').attr('value',data.drugDict.drugName);

                    })
        }
        function search() {
            var form=$("#searchDrugFlowAccount");
            form.attr("onsubmit","return loadDivForm('mainCenterDiv','searchDrugFlowAccount','${ctx}/drug/drugStock/drugFlowAccountBack');")
            form.submit();
        }
</script>